package cn.yunhe.spring.mybatis.service.impl;

import cn.yunhe.spring.mybatis.dao.GoodsMapper;
import cn.yunhe.spring.mybatis.model.Goods;
import cn.yunhe.spring.mybatis.model.Page;
import cn.yunhe.spring.mybatis.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by Administrator on 2016/11/29.
 */
@Service("goodsService")
public class GoodsServiceImpl implements IGoodsService{
    @Autowired
    private GoodsMapper goodsMapper;
    public Goods getGoods(Goods goods) {
        return goodsMapper.getGoods(goods);
    }

    public void addGoods(Goods goods) {
        goodsMapper.addGoods(goods);
    }

    public Page queryGoods(Map<String, Object> cond) {
        Page page=new Page();
        page.setTotalNum(goodsMapper.getLikeCount(cond));//总记录数

        int pageSize = Integer.parseInt(String.valueOf(cond.get("pageSize")));//每页显示多少条数据
		int curPageNum = Integer.parseInt(String.valueOf(cond.get("pageNum")));//获得当前页数据

        page.setCurPageNum(curPageNum);//设置当前页吗
        page.setTotalPage(page.getTotalNum()/pageSize+(page.getTotalNum()%pageSize==0?0:1));//总页数
        page.setResult(goodsMapper.getLikeGoods(cond));
        return page;
    }

    public void delGoods(Goods goods) {
        goodsMapper.deleteGoods(goods);
    }

    public void editGoods(Goods goods) {
        goodsMapper.editGoods(goods);
    }
}
